/**
 *kuwang
 * 2019年9月25日
 */
package com.yidu.privilege.Action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.yidu.privilege.Service.ModuleService;
import com.yidu.privilege.Utils.BaseMessage;
import com.yidu.privilege.Utils.Pages;
import com.yidu.privilege.vo.ModuleVo;
import com.yidu.utils.RedisUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author kuwang
 *
 * 2019年9月25日 上午9:25:32
 */

@Controller
@RequestMapping("/ModuleAction")
public class ModuleController {
	/**
	 *模块service
	 */
	@Resource
	ModuleService moduleService ;

	/**
	 * 查所有
	 * @param vo
	 * @param pa
	 * @return
	 */
	@RequestMapping("findAll")
	@ResponseBody
	public Map<String, Object> findAll(ModuleVo vo, Pages pa){
		//System.out.println(pa.getLimit()+"==========="+pa.getPage());
		List<ModuleVo> list=moduleService.findAll(vo,pa);
		
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("code",0);
		map.put("msg","");
		map.put("count",moduleService.count(vo));
		map.put("data",list);
		
		return map;
	}

	/**
	 * id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("findAlla")
	@ResponseBody
	public List findAlla(Integer id){
	
		
		return moduleService.findAll(id);
	}
	/**
	 * id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("findAlla2")
	@ResponseBody
	public List findAlla2(Integer roId){
	
		
		return moduleService.findAll2(roId);
	}
	/**
	 * id查询
	 * @param usId
	 * @return
	 */
	@RequestMapping("find")
	@ResponseBody
	public List find(Integer usId){
		
		return moduleService.findcha(usId);
	}
	/**
	 * id查询
	 * @param modId
	 * @return
	 */
	@RequestMapping("findbyid")
	@ResponseBody
	public ModuleVo findbyid(Integer modId){
		
		return moduleService.findbyid(modId);
	}

	/**
	 * 修改增加
	 * @param vo
	 * @return
	 */
	@RequestMapping("addOrupdate")
	@ResponseBody
	public BaseMessage addOrupdate(ModuleVo vo){
		

		int i=moduleService.addOrupdate(vo);

		BaseMessage be=new BaseMessage();
		if (i>0){
			be.setState(1);
		}else{
			be.setState(0);
		}


		return be;
	}

	/**
	 * 删除
	 * @param modId
	 * @return
	 */
	@RequestMapping("delete")
	@ResponseBody
	public BaseMessage delete(Integer modId){
		
		int i=moduleService.delete(modId);
		BaseMessage be=new BaseMessage();
		if (i>0){
			be.setState(1);
		}else{
			be.setState(0);
		}
		return be;
	}
	
	
	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("deleteAll")
	@ResponseBody
	public BaseMessage deleteAll(String ids) {
		
		BaseMessage bm = new BaseMessage();
		bm.setState(1);
		moduleService.deleteAll(ids);
		bm.setMsg("删除成功!");
		return bm ;
	}
	
	
}
